<?php
//include "../public/common/config.php";
include "../public/common/common.php";

//print_r($result);
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=divice-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
		<link href="<?php echo $publicPath?>css/bootstrap.min.css" rel="stylesheet"/>
		<script src="<?php echo $publicPath?>jQuery/jquery-3.1.1.min.js"></script>
		<title></title>
		<script type="text/javascript">
			$(function(){

			    				
				//状态显示
				$.ajax({
		            data: {
				        url:"www.kankanwu.com"
				    },
		            url: 'http://spider.ikanmore.com/job/status',
		            type:"GET",
		            dataType: 'json',
		            success: function(data){
		            	if(data.errCode == 0){
			        		$('.spider .kankanwu .status').text(data.status);
			        	}
		            },
		            error: function(textStatus){
		                console.log(textStatus);
		            }
		        });
		        //状态显示
		        
		        //开始爬取
		        $('.start>a').click(function(){
		        	$.ajax({
			            data: {
					        url:"www.kankanwu.com"
					    },
			            url: 'http://spider.ikanmore.com/job/run',
			            type:"POST",
			            dataType: 'json',
			            success: function(data){
			            	if(data.errCode == 0){
				        		$.ajax({
						            data: {
								        url:"www.kankanwu.com"
								    },
						            url: 'http://spider.ikanmore.com/job/status',
						            type:"GET",
						            dataType: 'json',
						            success: function(data){
						            	console.log(data);
						            	console.log(1);
						            	if(data.errCode == 0){
							        		$('.spider .kankanwu .status').text(data.status);
							        	}
						            },
						            error: function(textStatus){
						                console.log(textStatus);
						            }
						        });
				        	}
			            },
			            error: function(textStatus){
			                console.log(textStatus);
			            }
			        });
		        });
		        //开始爬取

				//停止爬取
		        $('.stop>a').click(function(){
		        	$.ajax({
			            data: {
					        url:"www.kankanwu.com"
					    },
			            url: 'http://spider.ikanmore.com/job/kill',
			            type:"POST",
			            dataType: 'json',
			            success: function(data){
			            	if(data.errCode == 0){
				        		$.ajax({
						            data: {
								        url:"www.kankanwu.com"
								    },
						            url: 'http://spider.ikanmore.com/job/status',
						            type:"GET",
						            dataType: 'json',
						            success: function(data){
						            	if(data.errCode == 0){
							        		$('.spider .kankanwu .status').text(data.status);
							        	}
						            },
						            error: function(textStatus){
						            	console.log(2);
						                console.log(textStatus);
						            }
						        });
				        	}
			            },
			            error: function(textStatus){
			                console.log(textStatus);
			            }
			        });
		        });
		        //停止爬取


			});
			
		</script>
	</head>
	<body>
		<div class="panel panel-default">
            <div class="panel-heading">爬虫</div>
            <div class="panel-body spider">
                <table class="table table-striped table-hover table-bordered" >
                    <thead><tr><th>#</th><th>爬虫网址</th><th>状态</th><th>开始</th><th>停止</th><th>标准输出</th><th>错误输出</th></tr></thead>
                    <tbody>
                    	<tr class="kankanwu">
                    		<td>1</td>
                    		<td>www.kankanwu.com</td>
                    		<td class="status"></td>
                    		<td class="start"><a href="javascript:;">开始</a></td>
                    		<td class="stop"><a href="javascript:;">结束</a></td>
                    		<td class="stdout"><a href="http://spider.ikanmore.com/job/stdout?url=www.kankanwu.com" target="_blank">标准输出</a></td>
                    		<td class="stderr"><a href="http://spider.ikanmore.com/job/stderr?url=www.kankanwu.com" target="_blank">错误输出</a></td>
                    	</tr>
                    </tbody>
                </table>
            </div>
        </div>
	</body>	
</html>